package com.co.controller;

import java.util.HashMap;

import javax.swing.UnsupportedLookAndFeelException;

import com.co.utils.Constants;
import com.co.utils.JPage;
import com.co.utils.Language;
import com.co.utils.XMLReader;

public class GlobalConfigurationManager {

	private static GlobalConfigurationManager globalConfigurationManagerInstance;

	private static final String PATH = "C:\\Projects\\COdontologicos\\conf\\es\\pageProperties.xml";
	HashMap pageProperties = null;

	private Language appLanguage = Language.getDefaultLanguage();
	private String lookAndFeelValue = null;
	private String pageTitle = null;

	public GlobalConfigurationManager() {
		pageProperties = new HashMap();
	}

	public static GlobalConfigurationManager getInstance() {
		if (globalConfigurationManagerInstance == null) {
			globalConfigurationManagerInstance = new GlobalConfigurationManager();
		}
		return globalConfigurationManagerInstance;
	}

	public void setLanguage(Language lang) {
		// mapear al xml con las leyendas en el lenguaje correspondiente.
		appLanguage = lang;
		// write en el ocnfig.
		// buscar leyendas en ese idioma
		// leyendas-es.xml
	}

	public void configureLookAndFeel() {

		XMLReader xmlReader = com.co.utils.XMLReader.getInstance();
		xmlReader.setFilePath(PATH);
		if (!xmlReader.getLookAndFeelValue().equals("")) {
			lookAndFeelValue = xmlReader.getLookAndFeelValue();
		}
	}

	public String getLookAndFeel() {
		if (getLookAndFeel() != null)
			return getLookAndFeel();
		return Constants.DEFAULT_LOOK_AND_FEEL;
	}

	public String getPageTitle() {
		return null;
	}

	public void configurePage(JPage page) {
		page.pack();
		String title = "Mi titulo";
		page.setTitle(title);
		// this.setSize(1024, 332);

		int windowsModal = page.MAXIMIZED_BOTH;
		page.setExtendedState(windowsModal);

		// Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		// System.out.println(dim.width + " - " + dim.height);

		setLookAndFeelToPage();
	}

	private void setLookAndFeelToPage() {
		try {
			javax.swing.UIManager.setLookAndFeel(lookAndFeelValue);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
